<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QStackedWidget Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QStackedWidget Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QStackedWidget class provides a stack of widgets where only
one widget is visible at a time. <a href="#details">More...</a></p>

<p>Inherits <a href="qframe.html">QFrame</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qstackedwidget.html#QStackedWidget">__init__</a></b> (<i>self</i>, QWidget&#160;<i>parent</i>&#160;=&#160;None)</li><li><div class="fn" />int <b><a href="qstackedwidget.html#addWidget">addWidget</a></b> (<i>self</i>, QWidget&#160;<i>w</i>)</li><li><div class="fn" />int <b><a href="qstackedwidget.html#count">count</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qstackedwidget.html#currentIndex">currentIndex</a></b> (<i>self</i>)</li><li><div class="fn" />QWidget <b><a href="qstackedwidget.html#currentWidget">currentWidget</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qstackedwidget.html#event">event</a></b> (<i>self</i>, QEvent&#160;<i>e</i>)</li><li><div class="fn" />int <b><a href="qstackedwidget.html#indexOf">indexOf</a></b> (<i>self</i>, QWidget)</li><li><div class="fn" />int <b><a href="qstackedwidget.html#insertWidget">insertWidget</a></b> (<i>self</i>, int&#160;<i>index</i>, QWidget&#160;<i>w</i>)</li><li><div class="fn" /><b><a href="qstackedwidget.html#removeWidget">removeWidget</a></b> (<i>self</i>, QWidget&#160;<i>w</i>)</li><li><div class="fn" /><b><a href="qstackedwidget.html#setCurrentIndex">setCurrentIndex</a></b> (<i>self</i>, int&#160;<i>index</i>)</li><li><div class="fn" /><b><a href="qstackedwidget.html#setCurrentWidget">setCurrentWidget</a></b> (<i>self</i>, QWidget&#160;<i>w</i>)</li><li><div class="fn" />QWidget <b><a href="qstackedwidget.html#widget">widget</a></b> (<i>self</i>, int)</li></ul><h3>Special Methods</h3><ul><li><div class="fn" /> <b><a href="qstackedwidget.html#__len__">__len__</a></b> (<i>self</i>)</li></ul><h3>Qt Signals</h3><ul><li><div class="fn" />void <b><a href="qstackedwidget.html#currentChanged">currentChanged</a></b> (int)</li><li><div class="fn" />void <b><a href="qstackedwidget.html#widgetRemoved">widgetRemoved</a></b> (int)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QStackedWidget class provides a stack of widgets where only
one widget is visible at a time.</p>
<p>QStackedWidget can be used to create a user interface similar to
the one provided by <a href="qtabwidget.html">QTabWidget</a>. It is
a convenience layout widget built on top of the <a href="qstackedlayout.html">QStackedLayout</a> class.</p>
<p>Like <a href="qstackedlayout.html">QStackedLayout</a>,
QStackedWidget can be constructed and populated with a number of
child widgets ("pages"):</p>
<pre class="cpp">
     <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>firstPageWidget <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qwidget.html">QWidget</a></span>;
     <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>secondPageWidget <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qwidget.html">QWidget</a></span>;
     <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>thirdPageWidget <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qwidget.html">QWidget</a></span>;

     <span class="type">QStackedWidget</span> <span class="operator">*</span>stackedWidget <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QStackedWidget</span>;
     stackedWidget<span class="operator">-</span><span class="operator">&gt;</span>addWidget(firstPageWidget);
     stackedWidget<span class="operator">-</span><span class="operator">&gt;</span>addWidget(secondPageWidget);
     stackedWidget<span class="operator">-</span><span class="operator">&gt;</span>addWidget(thirdPageWidget);

     <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>layout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>;
     layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(stackedWidget);
     setLayout(layout);
</pre>
<p>QStackedWidget provides no intrinsic means for the user to
switch page. This is typically done through a <a href="qcombobox.html">QComboBox</a> or a <a href="qlistwidget.html">QListWidget</a> that stores the titles of the
QStackedWidget's pages. For example:</p>
<pre class="cpp">
     <span class="type"><a href="qcombobox.html">QComboBox</a></span> <span class="operator">*</span>pageComboBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcombobox.html">QComboBox</a></span>;
     pageComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">"Page 1"</span>));
     pageComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">"Page 2"</span>));
     pageComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">"Page 3"</span>));
     connect(pageComboBox<span class="operator">,</span> SIGNAL(activated(<span class="type">int</span>))<span class="operator">,</span>
             stackedWidget<span class="operator">,</span> SLOT(setCurrentIndex(<span class="type">int</span>)));
</pre>
<p>When populating a stacked widget, the widgets are added to an
internal list. The <a href="qstackedwidget.html#indexOf">indexOf</a>() function returns the
index of a widget in that list. The widgets can either be added to
the end of the list using the <a href="qstackedwidget.html#addWidget">addWidget</a>() function, or
inserted at a given index using the <a href="qstackedwidget.html#insertWidget">insertWidget</a>() function. The
<a href="qstackedwidget.html#removeWidget">removeWidget</a>()
function removes a widget from the stacked widget. The number of
widgets contained in the stacked widget, can be obtained using the
<a href="qstackedwidget.html#count-prop">count</a>() function.</p>
<p>The <a href="qstackedwidget.html#widget">widget</a>() function
returns the widget at a given index position. The index of the
widget that is shown on screen is given by <a href="qstackedwidget.html#currentIndex-prop">currentIndex</a>() and can
be changed using <a href="qstackedwidget.html#currentIndex-prop">setCurrentIndex</a>(). In a
similar manner, the currently shown widget can be retrieved using
the <a href="qstackedwidget.html#currentWidget">currentWidget</a>()
function, and altered using the <a href="qstackedwidget.html#setCurrentWidget">setCurrentWidget</a>()
function.</p>
<p>Whenever the current widget in the stacked widget changes or a
widget is removed from the stacked widget, the <a href="qstackedwidget.html#currentChanged">currentChanged</a>() and
<a href="qstackedwidget.html#widgetRemoved">widgetRemoved</a>()
signals are emitted respectively.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QStackedWidget" />QStackedWidget.__init__ (<i>self</i>, <a href="qwidget.html">QWidget</a>&#160;<i>parent</i>&#160;=&#160;None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a <a href="qstackedwidget.html">QStackedWidget</a>
with the given <i>parent</i>.</p>
<p><b>See also</b> <a href="qstackedwidget.html#addWidget">addWidget</a>() and <a href="qstackedwidget.html#insertWidget">insertWidget</a>().</p>


<h3 class="fn"><a name="addWidget" />int QStackedWidget.addWidget (<i>self</i>, <a href="qwidget.html">QWidget</a>&#160;<i>w</i>)</h3><p>The <i>w</i> argument has it's ownership transferred to Qt.</p><p>Appends the given <i>widget</i> to the <a href="qstackedwidget.html">QStackedWidget</a> and returns the index
position. Ownership of <i>widget</i> is passed on to the <a href="qstackedwidget.html">QStackedWidget</a>.</p>
<p>If the <a href="qstackedwidget.html">QStackedWidget</a> is empty
before this function is called, <i>widget</i> becomes the current
widget.</p>
<p><b>See also</b> <a href="qstackedwidget.html#insertWidget">insertWidget</a>(), <a href="qstackedwidget.html#removeWidget">removeWidget</a>(), and <a href="qstackedwidget.html#setCurrentWidget">setCurrentWidget</a>().</p>


<h3 class="fn"><a name="count" />int QStackedWidget.count (<i>self</i>)</h3><h3 class="fn"><a name="currentIndex" />int QStackedWidget.currentIndex (<i>self</i>)</h3><h3 class="fn"><a name="currentWidget" /><a href="qwidget.html">QWidget</a> QStackedWidget.currentWidget (<i>self</i>)</h3><p>Returns the current widget, or 0 if there are no child
widgets.</p>
<p><b>See also</b> <a href="qstackedwidget.html#currentIndex-prop">currentIndex</a>() and
<a href="qstackedwidget.html#setCurrentWidget">setCurrentWidget</a>().</p>


<h3 class="fn"><a name="event" />bool QStackedWidget.event (<i>self</i>, <a href="qevent.html">QEvent</a>&#160;<i>e</i>)</h3><p>Reimplemented from <a href="qobject.html#event">QObject.event</a>().</p>


<h3 class="fn"><a name="indexOf" />int QStackedWidget.indexOf (<i>self</i>, <a href="qwidget.html">QWidget</a>)</h3><p>Returns the index of the given <i>widget</i>, or -1 if the given
<i>widget</i> is not a child of the <a href="qstackedwidget.html">QStackedWidget</a>.</p>
<p><b>See also</b> <a href="qstackedwidget.html#currentIndex-prop">currentIndex</a>() and
<a href="qstackedwidget.html#widget">widget</a>().</p>


<h3 class="fn"><a name="insertWidget" />int QStackedWidget.insertWidget (<i>self</i>, int&#160;<i>index</i>, <a href="qwidget.html">QWidget</a>&#160;<i>w</i>)</h3><p>The <i>w</i> argument has it's ownership transferred to Qt.</p><p>Inserts the given <i>widget</i> at the given <i>index</i> in the
<a href="qstackedwidget.html">QStackedWidget</a>. Ownership of
<i>widget</i> is passed on to the <a href="qstackedwidget.html">QStackedWidget</a>. If <i>index</i> is out of
range, the <i>widget</i> is appended (in which case it is the
actual index of the <i>widget</i> that is returned).</p>
<p>If the <a href="qstackedwidget.html">QStackedWidget</a> was
empty before this function is called, the given <i>widget</i>
becomes the current widget.</p>
<p>Inserting a new widget at an index less than or equal to the
current index will increment the current index, but keep the
current widget.</p>
<p><b>See also</b> <a href="qstackedwidget.html#addWidget">addWidget</a>(), <a href="qstackedwidget.html#removeWidget">removeWidget</a>(), and <a href="qstackedwidget.html#setCurrentWidget">setCurrentWidget</a>().</p>


<h3 class="fn"><a name="removeWidget" />QStackedWidget.removeWidget (<i>self</i>, <a href="qwidget.html">QWidget</a>&#160;<i>w</i>)</h3><p>Removes <i>widget</i> from the <a href="qstackedwidget.html">QStackedWidget</a>. i.e., <i>widget</i> is
<i>not</i> deleted but simply removed from the stacked layout,
causing it to be hidden.</p>
<p><b>Note:</b> Ownership of <i>widget</i> reverts to the
application.</p>
<p><b>See also</b> <a href="qstackedwidget.html#addWidget">addWidget</a>(), <a href="qstackedwidget.html#insertWidget">insertWidget</a>(), and <a href="qstackedwidget.html#currentWidget">currentWidget</a>().</p>


<h3 class="fn"><a name="setCurrentIndex" />QStackedWidget.setCurrentIndex (<i>self</i>, int&#160;<i>index</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void setCurrentIndex(int)</tt>.</p><h3 class="fn"><a name="setCurrentWidget" />QStackedWidget.setCurrentWidget (<i>self</i>, <a href="qwidget.html">QWidget</a>&#160;<i>w</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void setCurrentWidget(QWidget *)</tt>.</p><p>Sets the current widget to be the specified <i>widget</i>. The
new current widget must already be contained in this stacked
widget.</p>
<p><b>See also</b> <a href="qstackedwidget.html#currentWidget">currentWidget</a>() and
<a href="qstackedwidget.html#currentIndex-prop">setCurrentIndex</a>().</p>


<h3 class="fn"><a name="widget" /><a href="qwidget.html">QWidget</a> QStackedWidget.widget (<i>self</i>, int)</h3><p>Returns the widget at the given <i>index</i>, or 0 if there is
no such widget.</p>
<p><b>See also</b> <a href="qstackedwidget.html#currentWidget">currentWidget</a>() and
<a href="qstackedwidget.html#indexOf">indexOf</a>().</p>


<h3 class="fn"><a name="__len__" /> QStackedWidget.__len__ (<i>self</i>)</h3><hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="currentChanged" />void currentChanged (int)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted whenever the current widget changes.</p>
<p>The parameter holds the <i>index</i> of the new current widget,
or -1 if there isn't a new one (for example, if there are no
widgets in the <a href="qstackedwidget.html">QStackedWidget</a>).</p>
<p><b>See also</b> <a href="qstackedwidget.html#currentWidget">currentWidget</a>() and
<a href="qstackedwidget.html#setCurrentWidget">setCurrentWidget</a>().</p>


<h3 class="fn"><a name="widgetRemoved" />void widgetRemoved (int)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted whenever a widget is removed. The
widget's <i>index</i> is passed as parameter.</p>
<p><b>See also</b> <a href="qstackedwidget.html#removeWidget">removeWidget</a>().</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;snapshot-4.9.5-9eb6aac99275 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt&#160;4.8.3</td></tr></table></div></address></body></html>